package cn.edu.mju.user.controller;

import cn.edu.mju.common.entity.pojo.VipInfo;
import cn.edu.mju.common.entity.pojo.VipLevel;
import cn.edu.mju.common.entity.result.R;
import cn.edu.mju.user.service.IVipLevelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>Project: auth-service - VipLevelController
 * <p>Powered by 16423 On 2023-10-23 22:02:54
 *
 * @author 16423 [nanian]
 * @version 1.0
 * @since 17
 */
@RestController
@RequestMapping("/vipLevel")
public class VipLevelController {


    private static IVipLevelService iVipLevelService;


    @Autowired
    public VipLevelController(IVipLevelService iVipLevelService) {
        VipLevelController.iVipLevelService = iVipLevelService;
    }


    //TODO 获取会员价位 10.24
    @GetMapping("/getVipLevel")
    public R<List<VipLevel>> getLevelInfo(){
        List<VipLevel> list = iVipLevelService.list();
        return R.success(list);
    }

    //TODO 修改会员价格 10.24
    @PostMapping("/updatePrice")
    public R updatePrice(@RequestParam("levelId") String levelId,@RequestParam("price") Integer price){
        VipLevel vipLevel = new VipLevel();
        vipLevel.setLevelId(levelId);
        vipLevel.setLevelMoney(price);
        R r = new R<>();
        boolean i = iVipLevelService.update(vipLevel, new LambdaUpdateWrapper<VipLevel>().eq(VipLevel::getLevelId, levelId));
        if (i){
            r.setCode(200);
            r.setMsg("修改成功");
        }else {
            r.setCode(500);
            r.setMsg("修改失败");
        }
        return r;
    }



    //获取会员名称
    public static VipLevel getLevelName(Integer levelId){
        return iVipLevelService.getOne(new LambdaQueryWrapper<VipLevel>().eq(VipLevel::getLevelId, levelId));
    }

}